<template>

  <div class="user">
    <!--添加门店-->
    <div class="common-level-rail"><el-button size="small" type="primary" icon="Plus" @click="addClick" v-auth="'/agentaddress/agentaddress/add'">添加代理</el-button></div>

    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
          <el-table-column prop="store_id" label="代理ID" ></el-table-column>
		   <el-table-column prop="user_id" label="用户id"></el-table-column>
		  <el-table-column prop="money" label="签约金额"></el-table-column>
          <el-table-column prop="linkman" label="联系人"></el-table-column>
          <el-table-column prop="phone" label="联系电话" ></el-table-column>
		   <el-table-column prop="up_bili" label="专区上浮" ></el-table-column>
		   <el-table-column prop="type" label="代理类型" >
			   <template #default="scope">
			     <el-button  type="text" size="small" v-if="scope.row.type=='area'">区县</el-button>
			     <el-button  type="text" size="small" v-if="scope.row.type=='city'">市级</el-button>
			   </template>
		   </el-table-column>
          <el-table-column prop="detail_address" label="代理区域" ></el-table-column>
          <el-table-column prop="create_time" label="创建时间"></el-table-column>
          <el-table-column fixed="right" label="操作" >
            <template #default="scope"> 
			 <el-button @click="viewClick(scope.row)" type="text" size="small" >查看库存</el-button>
             <!-- <el-button @click="editClick(scope.row)" type="text" size="small" v-auth="'/store/store/edit'">编辑</el-button> -->
              <el-button @click="deleteClick(scope.row)" type="text" size="small" v-auth="'/agentaddress/agentaddress/delete'">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        ></el-pagination>
      </div>
    </div>
	<Edit v-if="open_edit" :open_edit="open_edit" :form="userModel" @closeDialog="closeDialogFunc($event, 'edit')"></Edit>
  </div>
</template>

<script>
import StoreApi from '@/api/store.js';
import Edit from './view.vue';
  import {deepClone} from '@/utils/base.js';
export default {
  components: {
	  Edit
  },
  inject: ['reload'],
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        user: '',
        region: ''
      },
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {}
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
	  closeDialogFunc(e, f) {
	    if (f == 'edit') {
	      this.open_edit = e.openDialog;
	      if (e.type == 'success') {
	      }
	    }
	  },
	  viewClick(item) {
	    this.userModel = deepClone(item);
	    this.open_edit = true;
	  },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },

    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = {};
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      StoreApi.ashoplist(Params, true)
        .then(data => {
          self.loading = false;
          self.tableData = data.data.list;
          self.totalDataNumber = data.data.total;
        })
        .catch(error => {});
    },

    /*打开添加*/
    addClick() {
      this.$router.push('/agentaddress/agentaddress/add');
    },

    /*打开编辑*/
    editClick(row) {
      let self = this;
      let params = row.store_id;
      this.$router.push({
        path: '/store/store/edit',
        // name: 'mallList',
        query: {
          store_id: params
        }
      });
    },

    /*删除*/
    deleteClick(row) {
      let self = this;
      ElMessageBox.confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          StoreApi.adeleteShop(
            {
              store_id: row.store_id
            },
            true
          )
            .then(data => {
              ElMessage({
                message: '恭喜你，删除成功',
                type: 'success'
              });
              self.getTableList();
            })
            .catch(error => {});
        })
        .catch(() => {});
    }
  }
};
</script>

<style></style>
